home *** CD-ROM | disk | FTP | other *** search
- unit Report;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, DCUDefs;
-
- type
- TReportForm = class(TForm)
- OKButton: TButton;
- Info: TMemo;
- SaveDialog1: TSaveDialog;
- Button1: TButton;
- procedure FormShow(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- p: PChar;
- Buff: PChar;
- Unknown: Boolean;
- Version: TDCUVersion;
- procedure PutStrUnderlined (const S: String);
- procedure PutStr (const S: String);
- procedure PutField (const Name, Val: String);
- function DCUReadString: String;
- function DCUDecodeNum: Integer;
- procedure DCUUnknown (Tag, Offset: Integer);
- procedure DCUDumpDFKRecord (const Typ: String);
- procedure DCUTypeSymUse (const Typ: String);
- procedure DCUDumpUsesRecord (const Typ: String);
- procedure DCUProcDeclaration;
- procedure DCUStdProcDeclaration;
- function DCUGetSymFlags (Flags: Integer): String;
- procedure DCUParamDeclaration;
- procedure DCUVariableDeclaration;
- procedure DCUConstDeclaration;
- procedure DCUTypeDeclaration;
- procedure DCUVMTDeclaration;
- procedure DCUTypedConstantDeclaration;
- procedure DCUThreadVarDeclaration;
- procedure DCUPutMagic (Flags: Integer);
- procedure DCUIncrementLevel;
- procedure DCUDecrementLevel;
- procedure DCUUnitFlags;
- public
- { Public declarations }
- end;
-
- implementation
-
- {$R *.DFM}
-
- procedure TReportForm.PutStr (const S: String);
- begin
- Info.Lines.Add (S);
- end;
-
- procedure TReportForm.PutStrUnderlined (const S: String);
- var
- Str: String;
- begin
- PutStr (S);
- Str := '';
- while Length (Str) < Length (S) do Str := Str + '=';
- PutStr (Str);
- PutStr ('');
- end;
-
- procedure TReportForm.PutField (const Name, Val: String);
- const
- Offset = 20;
- var
- S: String;
- begin
- S := Name;
- while Length (S) < Offset do S := S + ' ';
- PutStr (S + Val);
- end;
-
- procedure TReportForm.DCUUnknown (Tag, Offset: Integer);
- begin
- Unknown := True;
- PutField ('Unknown tag:', Format ('$%x at offset $%x', [Tag, Offset]));
- end;
-
- function TReportForm.DCUReadString: String;
- var
- Len: Byte;
- begin
- Result := '';
- Len := Ord (p^); Inc (p);
- while Len <> 0 do begin
- Result := Result + p^;
- Inc (p); Dec (Len);
- end;
- end;
-
- function TReportForm.DCUDecodeNum: Integer;
- const
- SizeNum: array [0..15] of Byte = ( 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5 );
- ShiftNum: array [0..15] of Byte = ( 25, 18, 25, 11, 25, 18, 25, 4, 25, 18, 25, 11, 25, 18, 25, 0 );
- var
- Idx: Byte;
- begin
- Idx := Ord (p^) and 15;
- Inc (p, SizeNum [Idx]);
- Result := PLongInt (p - 4)^ shr ShiftNum [Idx];
- end;
-
- function TReportForm.DCUGetSymFlags (Flags: Integer): String;
- begin
- Result := '[';
- if (Flags and 1) <> 0 then Result := Result + 'value, ';
- if (Flags and 2) <> 0 then Result := Result + 'assignable, ';
- if (Flags and 4) <> 0 then Result := Result + 'constant, ';
- if (Flags and 8) <> 0 then Result := Result + 'reg, ';
- if (Flags and 16) <> 0 then Result := Result + 'mem, ';
- if (Flags and 32) <> 0 then Result := Result + 'adr, ';
- if (Flags and 64) <> 0 then Result := Result + 'exported, ';
- if (Flags and 128) <> 0 then Result := Result + 'link or qual, ';
- if Length (Result) > 1 then SetLength (Result, Length (Result) - 2);
- Result := Result + ']';
- end;
-
- procedure TReportForm.DCUParamDeclaration;
- var
- Flags: Integer;
- begin
- PutField ('Param:', DCUReadString);
- Flags := DCUDecodeNum;
- PutField ('ParamFlags:', '$' + IntToHex (Flags, 8) + DCUGetSymFlags (Flags));
- PutField ('ParamType:', IntToStr (DCUDecodeNum));
- PutField ('ParamLoc', IntToStr (DCUDecodeNum));
- PutStr ('');
- end;
-
- procedure TReportForm.DCUTypedConstantDeclaration;
- var
- Flags: Integer;
- begin
- PutField ('TypedConstant:', DCUReadString);
- Flags := DCUDecodeNum;
- PutField ('ParamFlags:', '$' + IntToHex (Flags, 8) + DCUGetSymFlags (Flags));
- DCUPutMagic (Flags);
- PutField ('typedconst1:', '$' + IntToHex (DCUDecodeNum, 8));
- PutField ('typedconst2:', '$' + IntToHex (DCUDecodeNum, 8));
- PutStr ('');
- end;
-
- procedure TReportForm.DCUConstDeclaration;
- var
- Flags: Integer;
- begin
- PutField ('Constant:', DCUReadString);
- Flags := DCUDecodeNum;
- PutField ('ConstFlags:', '$' + IntToHex (Flags, 8) + DCUGetSymFlags (Flags));
- PutField ('Const1:', '$' + IntToHex (PLongInt (p)^, 8)); Inc (p, 4);
- PutField ('Const2:', '$' + IntToHex (DCUDecodeNum, 8));
- PutField ('Const3:', '$' + IntToHex (DCUDecodeNum, 8));
- PutField ('Value:', '$' + IntToHex (DCUDecodeNum, 8));
- PutStr ('');
- end;
-
- procedure TReportForm.DCUIncrementLevel;
- begin
- PutStr ('Increment Level:');
- PutStr ('');
- end;
-
- procedure TReportForm.DCUDecrementLevel;
- begin
- PutStr ('Decrement Level:');
- PutStr ('');
- end;
-
- procedure TReportForm.DCUUnitFlags;
- begin
- PutField ('Unit Flags:', 'Flags = $' + IntToHex (DCUDecodeNum, 8));
- if Version in [D4, D5, B3] then PutField ('Unit Flags:', 'Priority = $' + IntToHex (DCUDecodeNum, 8));
- PutStr ('');
- end;
-
- procedure TReportForm.DCUPutMagic (Flags: Integer);
- begin
- // Magic is only present for exported symbols.
- if (Flags and 64) <> 0 then begin
- PutField ('Magic:', '$' + IntToHex (PLongInt (p)^, 8));
- Inc (p, 4);
- end;
- end;
-
- procedure TReportForm.DCUThreadVarDeclaration;
- var
- Flags: Integer;
- begin
- PutField ('ThreadVar:', DCUReadString);
- Flags := DCUDecodeNum;
- PutField ('ThreadVarFlags:', '$' + IntToHex (Flags, 8) + DCUGetSymFlags (Flags));
- DCUPutMagic (Flags);
- PutField ('threadvar1:', '$' + IntToHex (DCUDecodeNum, 8));
- PutField ('threadvar2:', '$' + IntToHex (DCUDecodeNum, 8));
- PutStr ('');
- end;
-
- procedure TReportForm.DCUVariableDeclaration;
- var
- Flags: Integer;
- begin
- PutField ('Variable:', DCUReadString);
- Flags := DCUDecodeNum;
- PutField ('VarFlags:', '$' + IntToHex (Flags, 8) + DCUGetSymFlags (Flags));
- DCUPutMagic (Flags);
- PutField ('VarType:', '$' + IntToHex (DCUDecodeNum, 8));
- PutField ('VarLoc:', '$' + IntToHex (DCUDecodeNum, 8));
- PutStr ('');
- end;
-
- procedure TReportForm.DCUTypeDeclaration;
- var
- Flags: Integer;
- begin
- PutField ('Type:', DCUReadString);
- Flags := DCUDecodeNum;
- PutField ('TypeFlags:', '$' + IntToHex (Flags, 8) + DCUGetSymFlags (Flags));
- DCUPutMagic (Flags);
- PutField ('type1:', '$' + IntToHex (DCUDecodeNum, 8));
- PutStr ('');
- end;
-
- procedure TReportForm.DCUVMTDeclaration;
- var
- Flags: Integer;
- begin
- PutField ('VMT:', DCUReadString);
- Flags := DCUDecodeNum;
- PutField ('VMTFlags:', '$' + IntToHex (Flags, 8) + DCUGetSymFlags (Flags));
- DCUPutMagic (Flags);
- PutField ('vmt1:', '$' + IntToHex (DCUDecodeNum, 8));
- PutField ('vmt2:', '$' + IntToHex (DCUDecodeNum, 8));
- PutStr ('');
- end;
-
- procedure TReportForm.DCUStdProcDeclaration;
- var
- Flags: Integer;
- begin
- PutField ('StdProc:', DCUReadString);
- Flags := DCUDecodeNum;
- PutField ('StdProcFlags:', '$' + IntToHex (Flags, 8) + DCUGetSymFlags (Flags));
- PutField ('StdProcNum:', '$' + IntToHex (DCUDecodeNum, 8));
- PutStr ('');
- end;
-
- procedure TReportForm.DCUProcDeclaration;
- var
- Flags: Integer;
- begin
- PutField ('Procedure:', DCUReadString);
- Flags := DCUDecodeNum;
- PutField ('Proc Flags:', '$' + IntToHex (Flags, 8) + DCUGetSymFlags (Flags));
- DCUPutMagic (Flags);
- PutField ('proc1:', IntToStr (DCUDecodeNum));
- PutField ('Code Size:', IntToStr (DCUDecodeNum) + ' bytes');
- PutField ('ResultType:', IntToStr (DCUDecodeNum));
- PutStr ('');
-
- while not Unknown do begin
- Tag := Ord (p^); Inc (p);
- case Tag of
- Tag_End_Record: break; // All done!
- Tag_Param: DCUParamDeclaration;
- Tag_Variable: DCUVariableDeclaration;
- else DCUUnknown (Tag, p - Buff - 1);
- end;
- end;
- end;
-
- procedure TReportForm.DCUDumpUsesRecord (const Typ: String);
- var
- S, UnitName: String;
- modTime: LongInt;
- begin
- PutStrUnderlined (Format ('USES (%s)', [Typ]));
- UnitName := DCUReadString;
-
- PutField ('UnitName:', UnitName);
- modtime := PLongInt (p)^; Inc (p, 4);
- if modtime = 0 then S := '00000000' else try
- S := FormatDateTime ('dddd, mmmm d, yyyy, hh:mm AM/PM', FileDateToDateTime (modtime));
- except
- { Eat exceptions if modtime is invalid } ;
- end;
-
- PutField ('Modification Time:', S);
-
- while not Unknown do begin
- Tag := Ord (p^); Inc (p);
- case Tag of
- Tag_End_Record: break; // All done!
- Tag_Type_Use: DCUTypeSymUse ('Used Type:');
- Tag_Sym_Use: DCUTypeSymUse ('Used Symbol:');
- else DCUUnknown (Tag, p - Buff - 1);
- end;
- end;
-
- PutStr ('');
- end;
-
- procedure TReportForm.DCUTypeSymUse (const Typ: String);
- var
- TypName: String;
- begin
- TypName := DCUReadString;
- PutField (Typ, TypName + ' (Magic: $' + IntToHex (PLongInt (p)^, 8) + ')');
- Inc (p, 4);
- end;
-
- procedure TReportForm.DCUDumpDFKRecord (const Typ: String);
- var
- modtime: LongInt;
- begin
- PutField (Typ + ':', DCUReadString);
-
- try
- modtime := PLongInt (p)^; Inc (p, 4);
- PutField ('Modification Time:', FormatDateTime ('dddd, mmmm d, yyyy, hh:mm AM/PM', FileDateToDateTime (modtime)));
- except
- { Eat exceptions if modtime is invalid } ;
- end;
-
- PutField ('File Index:', IntToStr (DCUDecodeNum));
- PutStr ('');
- end;
-
- procedure TReportForm.FormShow(Sender: TObject);
- var
- fs: TFileStream;
- begin
- fs := TFileStream.Create (Caption, fmOpenRead);
- try
- PutStrUnderlined (Format ('Information on %s', [Caption]));
- Caption := 'DCU Report information';
- GetMem (Buff, fs.Size);
- fs.Read (Buff^, fs.Size);
- finally
- fs.Free;
- end;
-
- if Buff <> Nil then try
- p := Buff;
- // Get version number in an easily usable form
- case PLongInt (p)^ of
- D2Magic: Version := D2;
- D3Magic: Version := D3;
- D4Magic: Version := D4;
- D5Magic: Version := D5;
- B3Magic: Version := B3;
- end;
-
- // point at first byte of interest in DCU image
- Inc (p, 12);
- // If this isn't a Delphi 2 file, then there's an unknown 32-bit field to skip..
- if Version <> D2 then Inc (p, 4);
- // Now skip the ever-empty string field
- DCUReadString;
-
- while not Unknown do begin
- Tag := Ord (p^); Inc (p);
- case Tag of
- Tag_End: break; // All done!
- Tag_Int_Use: DCUDumpUsesRecord ('Interface');
- Tag_Imp_Use: DCUDumpUsesRecord ('Implementation');
- Tag_DLL_Import: DCUDumpUsesRecord ('DLL Import');
- Tag_DFK_Source: DCUDumpDFKRecord ('Source File');
- Tag_DFK_Object: DCUDumpDFKRecord ('Object File');
- Tag_DFK_Resource: DCUDumpDFKRecord ('Resource File');
- Tag_DFK_TheAdr: DCUDumpDFKRecord ('Tag_DFK_TheAdr ????');
- Tag_Proc: DCUProcDeclaration;
- Tag_StdProc: DCUStdProcDeclaration;
- Tag_Const: DCUConstDeclaration;
- Tag_VMT: DCUVMTDeclaration;
- Tag_Type: DCUTypeDeclaration;
- Tag_StructConst: DCUTypedConstantDeclaration;
- Tag_Variable: DCUVariableDeclaration;
- Tag_ThreadVar: DCUThreadVarDeclaration;
- Tag_Unit_Flags: DCUUnitFlags;
- Tag_Inc_Level: DCUIncrementLevel;
- Tag_Dec_Level: DCUDecrementLevel;
- else DCUUnknown (Tag, p - Buff - 1);
- end;
- end;
- finally
- FreeMem (Buff);
- end;
- end;
-
- procedure TReportForm.Button1Click(Sender: TObject);
- begin
- if SaveDialog1.Execute then Info.Lines.SaveToFile (SaveDialog1.FileName);
- end;
-
- end.
-